<!DOCTYPE html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">



 <script>(function(i,s,o,g,r,a,m){i["DaoVoiceObject"]=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;a.charset="utf-8";m.parentNode.insertBefore(a,m)})(window,document,"script",('https:' == document.location.protocol ? 'https:' : 'http:') + "//widget.daovoice.io/widget/b6dbddb6.js","daovoice")
 daovoice('init', {
  app_id: "3727e469"
});
daovoice('update');
 </script>




  
  
    
    
  <script src="/lib/pace/pace.min.js?v=1.0.2"></script>
  <link href="/lib/pace/pace-theme-center-circle.min.css?v=1.0.2" rel="stylesheet">







<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/icon.jpg?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/icon.jpg?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/icon.jpg?v=5.1.4">


  <link rel="mask-icon" href="/images/icon.jpg?v=5.1.4" color="#222">


  <link rel="manifest" href="/images/icon.jpg">




  <meta name="keywords" content="前端,js,vue,项目,axios,ElementUI,Mock.js," />





  <link rel="alternate" href="/atom.xml" title="Hexo" type="application/atom+xml" />






<meta name="description" content="正式开发msm阶段登录页面配置路由 在 src\views 目录下新建 login 目录及此目录下新建文件 index.vue说明：通过 import Login from ‘.&#x2F;views&#x2F;login’ 导入组件，当前只指定了组件路径，默认导入的就是指定路径下的 index.vue 组件 在 src\router.js 中配置路由（把原有的路由配置删除），如下：、 123456789101112">
<meta property="og:type" content="article">
<meta property="og:title" content="msm会员系统----登录+会员管理模块">
<meta property="og:url" content="http://yoursite.com/2020/02/05/msm/msm%E4%BC%9A%E5%91%98%E7%B3%BB%E7%BB%9F----%E7%99%BB%E5%BD%95+%E4%BC%9A%E5%91%98%E7%AE%A1%E7%90%86%E6%A8%A1%E5%9D%97/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="正式开发msm阶段登录页面配置路由 在 src\views 目录下新建 login 目录及此目录下新建文件 index.vue说明：通过 import Login from ‘.&#x2F;views&#x2F;login’ 导入组件，当前只指定了组件路径，默认导入的就是指定路径下的 index.vue 组件 在 src\router.js 中配置路由（把原有的路由配置删除），如下：、 123456789101112">
<meta property="article:published_time" content="2020-02-04T16:55:00.000Z">
<meta property="article:modified_time" content="2020-02-06T12:45:50.860Z">
<meta property="article:author" content="alexhigger">
<meta property="article:tag" content="前端">
<meta property="article:tag" content="js">
<meta property="article:tag" content="vue">
<meta property="article:tag" content="项目">
<meta property="article:tag" content="axios">
<meta property="article:tag" content="ElementUI">
<meta property="article:tag" content="Mock.js">
<meta name="twitter:card" content="summary">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    version: '5.1.4',
    sidebar: {"position":"right","display":"post","offset":12,"b2t":"false            //返回顶部按钮（只对Pisces | Gemini两种风格有效）","scrollpercent":"true   //返回顶部按钮的百分比","onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2020/02/05/msm/msm会员系统----登录+会员管理模块/"/>





  <title>msm会员系统----登录+会员管理模块 | Hexo</title>
  








<meta name="generator" content="Hexo 4.2.0"></head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-right page-post-detail">
    <div class="headband"></div>

<a href="https://github.com/alexhigger" target="_blank" rel="noopener" class="github-corner" aria-label="View source on GitHub"><svg width="80" height="80" viewBox="0 0 250 250" style="fill:#151513; color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Hexo</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off"
             placeholder="搜索..." spellcheck="false"
             type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2020/02/05/msm/msm%E4%BC%9A%E5%91%98%E7%B3%BB%E7%BB%9F----%E7%99%BB%E5%BD%95+%E4%BC%9A%E5%91%98%E7%AE%A1%E7%90%86%E6%A8%A1%E5%9D%97/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="alexhigger">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/icon.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Hexo">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">msm会员系统----登录+会员管理模块</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2020-02-05T00:55:00+08:00">
                2020-02-05
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          
            <span class="post-meta-divider">|</span>
            <span class="page-pv"><i class="fa fa-file-o"></i>
            <span class="busuanzi-value" id="busuanzi_value_page_pv" ></span>
            </span>
          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  6k字
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  29分钟
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h1 id="正式开发msm阶段"><a href="#正式开发msm阶段" class="headerlink" title="正式开发msm阶段"></a>正式开发msm阶段</h1><h2 id="登录页面"><a href="#登录页面" class="headerlink" title="登录页面"></a>登录页面</h2><h3 id="配置路由"><a href="#配置路由" class="headerlink" title="配置路由"></a>配置路由</h3><ol>
<li>在 src\views 目录下新建 login 目录及此目录下新建文件 index.vue<br>说明：通过 import Login from ‘./views/login’ 导入组件，当前只指定了组件路径，默认导入的就是指定路径<br>下的 index.vue 组件</li>
<li>在 src\router.js 中配置路由（把原有的路由配置删除），如下：、 <figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> Vue <span class="keyword">from</span> <span class="string">"vue"</span>;</span><br><span class="line"><span class="keyword">import</span> Router <span class="keyword">from</span> <span class="string">"vue-router"</span>;</span><br><span class="line"><span class="comment">// 默认导入目录下的 index.vue 文件，等价于 ./views/login/index.vue</span></span><br><span class="line"><span class="keyword">import</span> Login <span class="keyword">from</span> <span class="string">'./views/login'</span></span><br><span class="line"></span><br><span class="line">Vue.use(Router);</span><br><span class="line"></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">default</span> <span class="keyword">new</span> Router(&#123;</span><br><span class="line">routes: [</span><br><span class="line">    &#123;</span><br><span class="line">    <span class="comment">// 登录页</span></span><br><span class="line">    path: <span class="string">'/login'</span>,</span><br><span class="line">    name: <span class="string">'login'</span>, <span class="comment">//路由名称</span></span><br><span class="line">    component: Login</span><br><span class="line">    &#125;</span><br><span class="line">    ],</span><br><span class="line">    </span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure></li>
<li>路由渲染出口，在 App.vue 中, 注意样式保持一致 <figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">template</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">"app"</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!-- 路由组件渲染出口 --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">router-view</span>&gt;</span><span class="tag">&lt;/<span class="name">router-view</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">template</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">style</span> &gt;</span></span><br><span class="line"><span class="css"><span class="comment">/* 上面不要加 scoped */</span></span></span><br><span class="line">body &#123;</span><br><span class="line">font-family: "微软雅黑";</span><br><span class="line"><span class="css"><span class="comment">/* 满屏显示, 不显示默认边距 margin:8px, */</span></span></span><br><span class="line">margin: 0px auto;</span><br><span class="line">&#125;</span><br><span class="line"><span class="tag">&lt;/<span class="name">style</span>&gt;</span></span><br></pre></td></tr></table></figure>
<hr>
<h3 id="表单"><a href="#表单" class="headerlink" title="表单"></a>表单</h3></li>
</ol>
<ul>
<li><p>利用elementui模板创建表单（样式+校验）</p>
</li>
<li><p>EasyMock 添加登陆认证模拟接口</p>
<ul>
<li>因为要访问EasyMock 模拟接口, 所以要把 接口地址改一下，在 .env.development 文件中修改如下：<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 使用 VUE_APP_ 开头的变量会被 webpack 自动加载</span></span><br><span class="line"><span class="comment"># 定义请求的基础URL, 方便跨域请求时使用</span></span><br><span class="line"><span class="string">VUE_APP_BASE_API</span> <span class="string">=</span> <span class="string">'/dev-api'</span></span><br><span class="line"><span class="comment"># 接口服务地址</span></span><br><span class="line"><span class="comment"># VUE_APP_SERVICE_URL = 'http://localhost:8001'</span></span><br><span class="line"><span class="comment"># Easy-Mock 接口服务地址</span></span><br><span class="line"><span class="string">VUE_APP_SERVICE_URL</span> <span class="string">=</span> <span class="string">'https://www.easy-mock.com/mock/5d3d62c0250e9354d3640960'</span></span><br></pre></td></tr></table></figure></li>
<li>配置 Mock.js</li>
</ul>
</li>
<li><p>在 src/api 下创建 login.js , 添加内容如下:</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> request <span class="keyword">from</span> <span class="string">'@/utils/request'</span></span><br><span class="line"><span class="comment">// 注意：导出的是普通成员函数</span></span><br><span class="line"><span class="comment">// 登录</span></span><br><span class="line"><span class="keyword">export</span> <span class="function"><span class="keyword">function</span> <span class="title">login</span>(<span class="params">username, password</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> request(&#123;</span><br><span class="line">        url: <span class="string">'/user/login'</span>,</span><br><span class="line">        method: <span class="string">'post'</span>,</span><br><span class="line">        data: &#123;</span><br><span class="line">            username,</span><br><span class="line">            password</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;)</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">// 获取用户信息</span></span><br><span class="line"><span class="keyword">export</span> <span class="function"><span class="keyword">function</span> <span class="title">getUserInfo</span>(<span class="params">token</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> request(&#123;</span><br><span class="line">        url: <span class="string">`/user/info/<span class="subst">$&#123;token&#125;</span>`</span>, <span class="comment">// 注意是反单引号 ``</span></span><br><span class="line">        method: <span class="string">'get'</span></span><br><span class="line">    &#125;)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>完整代码  </p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br></pre></td><td class="code"><pre><span class="line">&lt;template&gt;</span><br><span class="line">  &lt;div <span class="class"><span class="keyword">class</span></span>=<span class="string">"login-container"</span>&gt;</span><br><span class="line">    &lt;!-- :rules=<span class="string">"rules"</span> 表单验证, ref 相当于 id，:model 表单数据对象, label-width 表单域标签的的宽度 --&gt;</span><br><span class="line">    &lt;el-form :rules=<span class="string">"rules"</span> ref=<span class="string">"form"</span> :model=<span class="string">"form"</span> label-width=<span class="string">"80px"</span> <span class="class"><span class="keyword">class</span></span>=<span class="string">"login-form"</span>&gt;</span><br><span class="line">      &lt;h2 <span class="class"><span class="keyword">class</span></span>=<span class="string">"login-title"</span>&gt;会员管理系统&lt;<span class="regexp">/h2&gt;</span></span><br><span class="line"><span class="regexp">      &lt;!-- 注意： prop 是加在 el-form-item 组件上 --&gt;</span></span><br><span class="line"><span class="regexp">      &lt;el-form-item label="帐号" prop="username"&gt;</span></span><br><span class="line"><span class="regexp">        &lt;el-input v-model="form.username" placeholder="请输入帐号"&gt;&lt;/</span>el-input&gt;</span><br><span class="line">      &lt;<span class="regexp">/el-form-item&gt;</span></span><br><span class="line"><span class="regexp">      &lt;el-form-item label="密码" prop="password"&gt;</span></span><br><span class="line"><span class="regexp">        &lt;el-input type="password" v-model="form.password" placeholder="请输入密码"&gt;&lt;/</span>el-input&gt;</span><br><span class="line">      &lt;<span class="regexp">/el-form-item&gt;</span></span><br><span class="line"><span class="regexp">      &lt;el-form-item&gt;</span></span><br><span class="line"><span class="regexp">        &lt;el-button type="primary" @click="submitForm('form')"&gt;登录&lt;/</span>el-button&gt;</span><br><span class="line">      &lt;<span class="regexp">/el-form-item&gt;</span></span><br><span class="line"><span class="regexp">    &lt;/</span>el-form&gt;</span><br><span class="line">  &lt;<span class="regexp">/div&gt;</span></span><br><span class="line"><span class="regexp">&lt;/</span>template&gt;</span><br><span class="line"></span><br><span class="line">&lt;script&gt;</span><br><span class="line"><span class="keyword">import</span> &#123; login, getUserInfo &#125; <span class="keyword">from</span> <span class="string">"@/api/login"</span>;</span><br><span class="line"><span class="keyword">export</span> <span class="keyword">default</span> &#123;</span><br><span class="line">  methods: &#123;</span><br><span class="line">    <span class="comment">// 注意：按钮上调用的函数名要一致 submitForm</span></span><br><span class="line">    submitForm(formName) &#123;</span><br><span class="line">      <span class="keyword">this</span>.$refs[formName].validate(<span class="function"><span class="params">valid</span> =&gt;</span> &#123;</span><br><span class="line">        <span class="keyword">if</span> (valid) &#123;</span><br><span class="line">          <span class="comment">// 验证帐号和密码是否通过，</span></span><br><span class="line">          login(<span class="keyword">this</span>.form.username, <span class="keyword">this</span>.form.password).then(<span class="function"><span class="params">response</span> =&gt;</span> &#123;</span><br><span class="line">            <span class="keyword">const</span> resp = response.data;</span><br><span class="line">            <span class="built_in">console</span>.log(</span><br><span class="line">             resp,resp.flag</span><br><span class="line">            );</span><br><span class="line">            <span class="keyword">if</span> (resp.flag) &#123;</span><br><span class="line">              <span class="comment">// 通过，获取用户信息 异步请求</span></span><br><span class="line">              getUserInfo(resp.data.token).then(<span class="function"><span class="params">response</span> =&gt;</span> &#123;</span><br><span class="line">                <span class="comment">// 存入session中</span></span><br><span class="line">                <span class="keyword">const</span> respUser = response.data;</span><br><span class="line">                <span class="keyword">if</span> (respUser.flag) &#123;</span><br><span class="line">                  <span class="comment">// 将信息保存到浏览器的 localStorage 中</span></span><br><span class="line">                  <span class="built_in">console</span>.log(<span class="string">'userinfo'</span>,respUser.data)</span><br><span class="line">                  localStorage.setItem(</span><br><span class="line">                    <span class="string">"msm-user"</span>,</span><br><span class="line">                    <span class="built_in">JSON</span>.stringify(respUser.data)</span><br><span class="line">                  );</span><br><span class="line">                  <span class="comment">// 方便后面重新验证</span></span><br><span class="line">                  localStorage.setItem(<span class="string">"msm-token"</span>, resp.data.token);</span><br><span class="line">                  <span class="comment">// 前往首页</span></span><br><span class="line">                  <span class="keyword">this</span>.$message(&#123;</span><br><span class="line">                    message: <span class="string">'恭喜你，这是一条成功消息'</span>,</span><br><span class="line">                    type: <span class="string">'success'</span></span><br><span class="line">                    &#125;);</span><br><span class="line">                  <span class="keyword">this</span>.$router.push(<span class="string">"/"</span>);</span><br><span class="line">                &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                  <span class="comment">// 获取信息失败, 弹出警告</span></span><br><span class="line">                  <span class="keyword">this</span>.$message(&#123;</span><br><span class="line">                    message: respUser.message,</span><br><span class="line">                    type: <span class="string">"warning"</span></span><br><span class="line">                  &#125;);</span><br><span class="line">                &#125;</span><br><span class="line">              &#125;);</span><br><span class="line">            &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">              <span class="comment">// 未通过,弹出警告</span></span><br><span class="line">              <span class="keyword">this</span>.$message(&#123;</span><br><span class="line">                message: resp.message,</span><br><span class="line">                type: <span class="string">"warning"</span></span><br><span class="line">              &#125;);</span><br><span class="line">            &#125;</span><br><span class="line">          &#125;);</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">          <span class="built_in">console</span>.log(<span class="string">"error submit!!"</span>);</span><br><span class="line">          <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;);</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;,</span><br><span class="line">  data() &#123;</span><br><span class="line">    <span class="keyword">return</span> &#123;</span><br><span class="line">      form: &#123;&#125;,</span><br><span class="line">      <span class="comment">// 表单校验</span></span><br><span class="line">      rules: &#123;</span><br><span class="line">        username: [</span><br><span class="line">          <span class="comment">// 对应el-form-item 的 prop 值</span></span><br><span class="line">          &#123; <span class="attr">required</span>: <span class="literal">true</span>, <span class="attr">message</span>: <span class="string">"帐号不能为空"</span>, <span class="attr">trigger</span>: <span class="string">"blur"</span> &#125;</span><br><span class="line">        ],</span><br><span class="line">        password: [&#123; <span class="attr">required</span>: <span class="literal">true</span>, <span class="attr">message</span>: <span class="string">"密码不能为空"</span>, <span class="attr">trigger</span>: <span class="string">"blur"</span> &#125;]</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;;</span><br><span class="line">&lt;<span class="regexp">/script&gt;</span></span><br><span class="line"><span class="regexp">&lt;/</span>script&gt;</span><br><span class="line">&lt;style scoped&gt;</span><br><span class="line">.login-form &#123;</span><br><span class="line">  width: <span class="number">350</span>px;</span><br><span class="line">  <span class="comment">/* 上下间隙150px, 左右自动 */</span></span><br><span class="line">  margin: <span class="number">160</span>px auto;</span><br><span class="line">  <span class="comment">/*透明背景色*/</span></span><br><span class="line">  background-color: rgb(<span class="number">255</span>, <span class="number">255</span>, <span class="number">255</span>, <span class="number">0.8</span>);</span><br><span class="line">  padding: <span class="number">30</span>px;</span><br><span class="line">  <span class="comment">/* 圆角 */</span></span><br><span class="line">  border-radius: <span class="number">20</span>px;</span><br><span class="line">&#125;</span><br><span class="line">.login-container &#123;</span><br><span class="line">  position: absolute;</span><br><span class="line">  width: <span class="number">100</span>%;</span><br><span class="line">  height: <span class="number">100</span>%;</span><br><span class="line">  background: url(<span class="string">"../../assets/login.jpg"</span>);</span><br><span class="line">  overflow: hidden;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/* 标题 */</span></span><br><span class="line">.login-title &#123;</span><br><span class="line">  text-align: center;</span><br><span class="line">  color: #303133;</span><br><span class="line">&#125;</span><br><span class="line">&lt;<span class="regexp">/style&gt;</span></span><br></pre></td></tr></table></figure>
</li>
</ul>
<hr>
<h2 id="项目布局"><a href="#项目布局" class="headerlink" title="项目布局"></a>项目布局</h2><h3 id="配置路由-1"><a href="#配置路由-1" class="headerlink" title="配置路由"></a>配置路由</h3><ul>
<li>在 src\components 目录下新建布局组件文件 Loyout.vue , 基础布局我们都放到 components 下面 </li>
<li>在 src\router.js 中增加路由配置<ul>
<li>导入路由组件<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 布局组件</span></span><br><span class="line"><span class="keyword">import</span> Layout <span class="keyword">from</span> <span class="string">'./components/Layout.vue'</span></span><br></pre></td></tr></table></figure></li>
<li>增加路由信息<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line"> <span class="comment">// 基础布局</span></span><br><span class="line"> path: <span class="string">'/'</span>,</span><br><span class="line"> name: <span class="string">'layout'</span>,</span><br><span class="line"> component: Layout</span><br><span class="line"> &#125;,</span><br></pre></td></tr></table></figure>
<h3 id="布局实现"><a href="#布局实现" class="headerlink" title="布局实现"></a>布局实现</h3></li>
</ul>
</li>
<li>在 src\components 目录下新建3个子目录存放子组件： AppHeader 、 AppNavbar 、 AppMain</li>
<li>在新建的3个子目录下分别新建 index.vue 文件</li>
<li>将 Layout.vue 文件中三大组成部分，分别把对应模板剪切到对应 index.vue 中。<ul>
<li>src\components\AppHeader\index.vue <figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">&lt;template&gt;</span><br><span class="line">&lt;div <span class="class"><span class="keyword">class</span></span>=<span class="string">"header"</span>&gt;头部&lt;<span class="regexp">/div&gt;</span></span><br><span class="line"><span class="regexp">&lt;/</span>template&gt;</span><br></pre></td></tr></table></figure></li>
</ul>
</li>
<li>在 Layout.vue 中使用 components 选项将3个组件作为子组件引入。 <figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">&lt;template&gt;</span><br><span class="line">&lt;div&gt;</span><br><span class="line">    &lt;!-- 头部区域 --&gt;</span><br><span class="line">    &lt;app-header /&gt;</span><br><span class="line">    &lt;!-- 左侧导航区域 --&gt;</span><br><span class="line">    &lt;app-navbar /&gt;</span><br><span class="line">    &lt;!-- 右侧主区域 --&gt;</span><br><span class="line">    &lt;app-main /&gt;</span><br><span class="line">&lt;<span class="regexp">/div&gt;</span></span><br><span class="line"><span class="regexp">&lt;/</span>template&gt;</span><br><span class="line"></span><br><span class="line">&lt;script&gt;</span><br><span class="line"><span class="comment">// 1. 导入子组件</span></span><br><span class="line"><span class="keyword">import</span> AppHeader <span class="keyword">from</span> <span class="string">"./AppHeader"</span>;</span><br><span class="line"><span class="keyword">import</span> AppNavbar <span class="keyword">from</span> <span class="string">"./AppNavbar"</span>;</span><br><span class="line"><span class="keyword">import</span> AppMain <span class="keyword">from</span> <span class="string">"./AppMain"</span>;</span><br><span class="line"><span class="keyword">export</span> <span class="keyword">default</span> &#123;</span><br><span class="line"><span class="comment">// 2. 注册为子组件</span></span><br><span class="line">components: &#123;</span><br><span class="line">    AppHeader, AppNavbar, AppMain</span><br><span class="line">&#125;</span><br><span class="line">&#125;;</span><br><span class="line">&lt;<span class="regexp">/script&gt;</span></span><br></pre></td></tr></table></figure>
<h3 id="头部区域实现"><a href="#头部区域实现" class="headerlink" title="头部区域实现"></a>头部区域实现</h3>右侧下拉菜单直接引用elementui的代码<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br></pre></td><td class="code"><pre><span class="line">&lt;template&gt;</span><br><span class="line">  &lt;div <span class="class"><span class="keyword">class</span></span>=<span class="string">"header"</span>&gt;</span><br><span class="line">    &lt;!-- 头部左侧Logo和标题 --&gt;</span><br><span class="line">    &lt;a href=<span class="string">"#/"</span>&gt;</span><br><span class="line">      &lt;img <span class="class"><span class="keyword">class</span></span>=<span class="string">"logo"</span> src=<span class="string">"@/assets/logo.png"</span> width=<span class="string">"25px"</span> /&gt;</span><br><span class="line">      &lt;span <span class="class"><span class="keyword">class</span></span>=<span class="string">"company"</span>&gt;Vue-会员管理系统&lt;<span class="regexp">/span&gt;</span></span><br><span class="line"><span class="regexp">    &lt;/</span>a&gt;</span><br><span class="line">    &lt;!-- 头部右侧下拉菜单 --&gt;</span><br><span class="line">    &lt;el-dropdown @command=<span class="string">"handleCommand"</span> &gt;</span><br><span class="line">      &lt;span <span class="class"><span class="keyword">class</span></span>=<span class="string">"el-dropdown-link"</span> &gt;</span><br><span class="line">        &lt;i <span class="class"><span class="keyword">class</span></span>=<span class="string">"el-icon-user"</span>&gt;<span class="xml"><span class="tag">&lt;/<span class="name">i</span>&gt;</span></span></span><br><span class="line">        admin</span><br><span class="line">        &lt;i <span class="class"><span class="keyword">class</span></span>=<span class="string">"el-icon-arrow-down el-icon--right"</span>&gt;<span class="xml"><span class="tag">&lt;/<span class="name">i</span>&gt;</span></span></span><br><span class="line">      &lt;<span class="regexp">/span&gt;</span></span><br><span class="line"><span class="regexp">      &lt;el-dropdown-menu slot="dropdown"&gt;</span></span><br><span class="line"><span class="regexp">        &lt;el-dropdown-item command="a" icon="el-icon-edit-outline"&gt;修改密码&lt;/</span>el-dropdown-item&gt;</span><br><span class="line">        &lt;el-dropdown-item command=<span class="string">"b"</span> icon=<span class="string">"el-icon-switch-button"</span>&gt;退出系统&lt;<span class="regexp">/el-dropdown-item&gt;</span></span><br><span class="line"><span class="regexp">      &lt;/</span>el-dropdown-menu&gt;</span><br><span class="line">    &lt;<span class="regexp">/el-dropdown&gt;</span></span><br><span class="line"><span class="regexp">  &lt;/</span>div&gt;</span><br><span class="line">&lt;<span class="regexp">/template&gt;</span></span><br><span class="line"><span class="regexp">&lt;script&gt;</span></span><br><span class="line"><span class="regexp">export default &#123;</span></span><br><span class="line"><span class="regexp">  methods: &#123;</span></span><br><span class="line"><span class="regexp">    handleCommand(command) &#123;</span></span><br><span class="line"><span class="regexp">      this.$message("click on item " + command);</span></span><br><span class="line"><span class="regexp">    &#125;</span></span><br><span class="line"><span class="regexp">  &#125;</span></span><br><span class="line"><span class="regexp">&#125;;</span></span><br><span class="line"><span class="regexp">&lt;/</span>script&gt;</span><br><span class="line">&lt;style scoped&gt;</span><br><span class="line">.logo &#123;</span><br><span class="line">  vertical-align: middle;</span><br><span class="line">  <span class="comment">/* 上 右 下 左 */</span></span><br><span class="line">  padding: <span class="number">0</span> <span class="number">10</span>px <span class="number">0</span> <span class="number">40</span>px;</span><br><span class="line">&#125;</span><br><span class="line">.company &#123;</span><br><span class="line">  position: absolute;</span><br><span class="line">  color: white;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/* 下拉菜单 */</span></span><br><span class="line">.el-dropdown &#123;</span><br><span class="line">  float: right;</span><br><span class="line">  margin-right: <span class="number">40</span>px;</span><br><span class="line">&#125;</span><br><span class="line">.el-dropdown-link &#123;</span><br><span class="line">  cursor: pointer;</span><br><span class="line">  color: #fff;</span><br><span class="line">&#125;</span><br><span class="line">&lt;<span class="regexp">/style&gt;</span></span><br></pre></td></tr></table></figure>
</li>
</ul>
<hr>
<h3 id="左侧导航实现"><a href="#左侧导航实现" class="headerlink" title="左侧导航实现"></a>左侧导航实现</h3><p>直接引用elementui的代码</p>
<ul>
<li>在 src\views 目录下创建 home、member、supplier、goods、staff 目录，并且每个目录下创建一个<br>index.vue</li>
<li>配置所有菜单路由信息，在 router.js 中配置如下：<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> Vue <span class="keyword">from</span> <span class="string">"vue"</span>;</span><br><span class="line"><span class="keyword">import</span> Router <span class="keyword">from</span> <span class="string">"vue-router"</span>;</span><br><span class="line"><span class="comment">// 默认导入目录下的 index.vue 文件，等价于 ./views/login/index.vue</span></span><br><span class="line"><span class="keyword">import</span> Login <span class="keyword">from</span> <span class="string">'./views/login'</span></span><br><span class="line"><span class="comment">// 布局组件</span></span><br><span class="line"><span class="keyword">import</span> Layout <span class="keyword">from</span> <span class="string">'./components/Layout.vue'</span></span><br><span class="line"><span class="keyword">import</span> Home <span class="keyword">from</span> <span class="string">'./views/home'</span></span><br><span class="line"><span class="keyword">import</span> Member <span class="keyword">from</span> <span class="string">'./views/member'</span></span><br><span class="line"><span class="keyword">import</span> Supplier <span class="keyword">from</span> <span class="string">'./views/supplier'</span></span><br><span class="line"><span class="keyword">import</span> Goods <span class="keyword">from</span> <span class="string">'./views/goods'</span></span><br><span class="line"><span class="keyword">import</span> Staff <span class="keyword">from</span> <span class="string">'./views/staff'</span></span><br><span class="line"></span><br><span class="line">Vue.use(Router);</span><br><span class="line"></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">default</span> <span class="keyword">new</span> Router(&#123;</span><br><span class="line">  routes: [</span><br><span class="line">    &#123;</span><br><span class="line">      <span class="comment">// 登录页</span></span><br><span class="line">      path: <span class="string">'/login'</span>,</span><br><span class="line">      name: <span class="string">'login'</span>, <span class="comment">//路由名称</span></span><br><span class="line">      component: Login</span><br><span class="line">    &#125;,</span><br><span class="line">    &#123;</span><br><span class="line">      <span class="comment">// 基础布局</span></span><br><span class="line">      path: <span class="string">'/'</span>,</span><br><span class="line">      name: <span class="string">'layout'</span>,</span><br><span class="line">      component: Layout,</span><br><span class="line">      redirect: <span class="string">'/home'</span>,<span class="comment">// 重定向到子路由</span></span><br><span class="line">      children: [</span><br><span class="line">        &#123;</span><br><span class="line">          path: <span class="string">'/home'</span>,</span><br><span class="line">          component: Home,</span><br><span class="line">          meta: &#123; <span class="attr">title</span>: <span class="string">'首页'</span> &#125;</span><br><span class="line">        &#125;,</span><br><span class="line">      ]</span><br><span class="line">    &#125;,</span><br><span class="line">    &#123;</span><br><span class="line">      <span class="comment">// 会员管理</span></span><br><span class="line">      path: <span class="string">'/member'</span>,</span><br><span class="line">      component: Layout,</span><br><span class="line">      children: [</span><br><span class="line">        &#123;</span><br><span class="line">          path: <span class="string">'/'</span>,</span><br><span class="line">          component: Member,</span><br><span class="line">          meta: &#123; <span class="attr">title</span>: <span class="string">'会员管理'</span> &#125;</span><br><span class="line">        &#125;</span><br><span class="line">      ]</span><br><span class="line">    &#125;,</span><br><span class="line">    &#123;</span><br><span class="line">      <span class="comment">// 供应商管理</span></span><br><span class="line">      path: <span class="string">'/supplier'</span>,</span><br><span class="line">      component: Layout,</span><br><span class="line">      children: [</span><br><span class="line">        &#123;</span><br><span class="line">          path: <span class="string">'/'</span>,</span><br><span class="line">          component: Supplier,</span><br><span class="line">          meta: &#123; <span class="attr">title</span>: <span class="string">'供应商管理'</span> &#125;</span><br><span class="line">        &#125;</span><br><span class="line">      ]</span><br><span class="line">    &#125;,</span><br><span class="line">    &#123;</span><br><span class="line">      <span class="comment">// 商品管理</span></span><br><span class="line">      path: <span class="string">'/goods'</span>,</span><br><span class="line">      component: Layout,</span><br><span class="line">      children: [</span><br><span class="line">        &#123;</span><br><span class="line">          path: <span class="string">'/'</span>,</span><br><span class="line">          component: Goods,</span><br><span class="line">          meta: &#123; <span class="attr">title</span>: <span class="string">'商品管理'</span> &#125;</span><br><span class="line">        &#125;</span><br><span class="line">      ]</span><br><span class="line">    &#125;,</span><br><span class="line">    &#123;</span><br><span class="line">      <span class="comment">// 员工管理</span></span><br><span class="line">      path: <span class="string">'/staff'</span>,</span><br><span class="line">      component: Layout,</span><br><span class="line">      children: [</span><br><span class="line">        &#123;</span><br><span class="line">          path: <span class="string">'/'</span>,</span><br><span class="line">          component: Staff,</span><br><span class="line">          meta: &#123; <span class="attr">title</span>: <span class="string">'员工管理'</span> &#125;,</span><br><span class="line">        &#125;</span><br><span class="line">      ]</span><br><span class="line">    &#125;,</span><br><span class="line">  ],</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>
</li>
</ul>
<hr>
<h3 id="右侧主区域实现"><a href="#右侧主区域实现" class="headerlink" title="右侧主区域实现"></a>右侧主区域实现</h3><ul>
<li>上方显示现在页面所在位置（例如：现在在员工管理页面）—-面包屑<ul>
<li>将 横向指示导航 抽取为子组件 AppMain\Link.vue<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">&lt;template&gt;</span><br><span class="line">  &lt;el-breadcrumb separator=<span class="string">"/"</span>&gt;</span><br><span class="line">    &lt;el-breadcrumb-item <span class="class"><span class="keyword">class</span></span>=<span class="string">"line"</span> :to=<span class="string">"&#123; path: $route.path &#125;"</span>&gt;&#123;&#123;$route.meta.title&#125;&#125;&lt;<span class="regexp">/el-breadcrumb-item&gt;</span></span><br><span class="line"><span class="regexp">  &lt;/</span>el-breadcrumb&gt;</span><br><span class="line">&lt;<span class="regexp">/template&gt;</span></span><br><span class="line"><span class="regexp">&lt;style scoped&gt;</span></span><br><span class="line"><span class="regexp">.el-breadcrumb &#123;</span></span><br><span class="line"><span class="regexp">  height: 10px;</span></span><br><span class="line"><span class="regexp">  padding: 20px;</span></span><br><span class="line"><span class="regexp">  border-radius: 4px;</span></span><br><span class="line"><span class="regexp">  /</span>* 投影 *<span class="regexp">/</span></span><br><span class="line"><span class="regexp">  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);</span></span><br><span class="line"><span class="regexp">&#125;</span></span><br><span class="line"><span class="regexp">.line &#123;</span></span><br><span class="line"><span class="regexp">  border-left: 3px solid #31c17b;</span></span><br><span class="line"><span class="regexp">  padding-left: 10px;</span></span><br><span class="line"><span class="regexp">&#125;</span></span><br><span class="line"><span class="regexp">&lt;/</span>style&gt;</span><br></pre></td></tr></table></figure></li>
<li>在 AppMain\index.vue 中导入 Link.vue<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">  &lt;template&gt;</span><br><span class="line">  &lt;div <span class="class"><span class="keyword">class</span></span>=<span class="string">"main"</span>&gt;</span><br><span class="line">    &lt;!-- v-show 当路由为 /home 不显示 --&gt;</span><br><span class="line">    &lt;app-link v-show=<span class="string">"$route.path !== '/home'"</span> /&gt;</span><br><span class="line">    &lt;!-- 子路由渲染出口 --&gt;</span><br><span class="line">/j    &lt;router-view&gt;<span class="xml"><span class="tag">&lt;/<span class="name">router-view</span>&gt;</span></span></span><br><span class="line">  &lt;<span class="regexp">/div&gt;</span></span><br><span class="line"><span class="regexp">  &lt;/</span>template&gt;</span><br><span class="line">  &lt;script&gt;</span><br><span class="line">  <span class="keyword">import</span> AppLink <span class="keyword">from</span> <span class="string">"./Link.vue"</span>;</span><br><span class="line">  <span class="keyword">export</span> <span class="keyword">default</span> &#123;</span><br><span class="line">    components: &#123; AppLink &#125;</span><br><span class="line">  &#125;;</span><br><span class="line">  &lt;<span class="regexp">/script&gt;</span></span><br><span class="line"><span class="regexp">  &lt;style scoped&gt;</span></span><br><span class="line"><span class="regexp">  &lt;/</span>style&gt;</span><br></pre></td></tr></table></figure>
<h2 id="退出功能"><a href="#退出功能" class="headerlink" title="退出功能"></a>退出功能</h2></li>
</ul>
</li>
<li>EasyMock 添加退出模拟接口</li>
<li>定义退出方法 logout <ul>
<li>在 src\api\login.js 添加退出方法 logout<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">export</span> <span class="function"><span class="keyword">function</span> <span class="title">logout</span>(<span class="params">token</span>) </span>&#123;</span><br><span class="line"><span class="keyword">return</span> request(&#123;</span><br><span class="line">url: <span class="string">'/user/logout'</span>,</span><br><span class="line">method: <span class="string">'post'</span>,</span><br><span class="line">data: &#123;</span><br><span class="line">token</span><br><span class="line">&#125;</span><br><span class="line">&#125;)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
</ul>
</li>
<li>组件中实现退出功能<ul>
<li>在 src\components\AppHeader\index.vue 实现退出功能<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><span class="line">&lt;script&gt;</span><br><span class="line"><span class="keyword">import</span> &#123; logout &#125; <span class="keyword">from</span> <span class="string">"@/api/login"</span>;</span><br><span class="line"><span class="keyword">export</span> <span class="keyword">default</span> &#123;</span><br><span class="line">  methods: &#123; </span><br><span class="line">    handleCommand(command) &#123;</span><br><span class="line">      <span class="keyword">switch</span> (command) &#123;</span><br><span class="line">        <span class="keyword">case</span> <span class="string">"a"</span>:</span><br><span class="line">          <span class="comment">//修改密码</span></span><br><span class="line">          <span class="keyword">this</span>.$message(<span class="string">"修改密码"</span>);</span><br><span class="line">          <span class="keyword">break</span>;</span><br><span class="line">        <span class="keyword">case</span> <span class="string">"b"</span>:</span><br><span class="line">          <span class="comment">//退出系统</span></span><br><span class="line">          logout(localStorage.getItem(localStorage.getItem(<span class="string">"msm-token"</span>))).then(<span class="function"><span class="params">response</span> =&gt;</span> &#123;</span><br><span class="line">              <span class="keyword">const</span> resp = response.data;</span><br><span class="line">              <span class="keyword">if</span> (resp.flag) &#123;</span><br><span class="line">                <span class="comment">//推出成功</span></span><br><span class="line">                <span class="comment">// 清除本地数据</span></span><br><span class="line">                localStorage.removeItem(<span class="string">"msm-token"</span>);</span><br><span class="line">                localStorage.removeItem(<span class="string">"msm-user"</span>);</span><br><span class="line">                <span class="comment">//回到登录页面</span></span><br><span class="line">                <span class="keyword">this</span>.$router.push(<span class="string">"/login"</span>);</span><br><span class="line">              &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">                <span class="keyword">this</span>.$message(&#123;</span><br><span class="line">                  message:resp.message,</span><br><span class="line">                  type: <span class="string">'warning'</span>,</span><br><span class="line">                  duration: <span class="number">500</span> <span class="comment">//弹出停留时间</span></span><br><span class="line">                &#125;)</span><br><span class="line">              &#125;</span><br><span class="line">            &#125;</span><br><span class="line">          );</span><br><span class="line">          <span class="keyword">break</span>;</span><br><span class="line">        <span class="keyword">default</span>:</span><br><span class="line">          <span class="keyword">break</span>;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;;</span><br><span class="line">&lt;<span class="regexp">/script&gt;</span></span><br></pre></td></tr></table></figure>
</li>
</ul>
</li>
</ul>
<hr>
<h2 id="权限验证"><a href="#权限验证" class="headerlink" title="权限验证"></a>权限验证</h2><ol>
<li>新建 src\permission.js 权限校验文件，代码如下:<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment">权限校验：</span></span><br><span class="line"><span class="comment">通过router路由前置钩子函数 beforeEach() ，</span></span><br><span class="line"><span class="comment">在跳转路由前进行拦截判断是否已经登录，</span></span><br><span class="line"><span class="comment">如果已登录，则进行路由跳转，如果没有则回到登录页</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="keyword">import</span> router <span class="keyword">from</span> <span class="string">'./router'</span></span><br><span class="line"><span class="keyword">import</span> &#123; getUserInfo &#125; <span class="keyword">from</span> <span class="string">'./api/login'</span></span><br><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment">前置路由钩子函数</span></span><br><span class="line"><span class="comment">to ：即将要进入的目标路由对象</span></span><br><span class="line"><span class="comment">from ：当前导航正要离开的路由对象</span></span><br><span class="line"><span class="comment">next : 调用该方法，进入目标路由</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line">router.beforeEach(<span class="function">(<span class="params">to, <span class="keyword">from</span>, next</span>) =&gt;</span> &#123;</span><br><span class="line">    <span class="comment">// 1.获取 token</span></span><br><span class="line">    <span class="keyword">const</span> token = localStorage.getItem(<span class="string">'msm-token'</span>)</span><br><span class="line">    <span class="keyword">if</span> (!token) &#123;</span><br><span class="line">        <span class="comment">//1.1如果没有获取到</span></span><br><span class="line">        <span class="comment">//要访问非登录页面，则不让访问，加到登录页面/login</span></span><br><span class="line">        <span class="keyword">if</span> (to.path !== <span class="string">'/login'</span>) &#123;</span><br><span class="line">            next(&#123; <span class="attr">path</span>: <span class="string">'/login'</span> &#125;)</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            next()</span><br><span class="line">        &#125;</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        <span class="comment">// 1.2 获取到token</span></span><br><span class="line">        <span class="comment">//     1.2.1请求路由 /login，那就去目标路由</span></span><br><span class="line">        <span class="keyword">if</span> (to.path === <span class="string">'/login'</span>) &#123;</span><br><span class="line">            next()</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            <span class="comment">//     1.2.2请求路由非登录页面，就通过token去获取用户信息</span></span><br><span class="line">            <span class="keyword">const</span> userinfo = localStorage.getItem(<span class="string">'msm-user'</span>)</span><br><span class="line">            <span class="keyword">if</span> (userinfo) &#123;</span><br><span class="line">                <span class="comment">//本地获取到，则直接去目标路由</span></span><br><span class="line">                next()</span><br><span class="line">            &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                <span class="comment">//     如果本地没有用户信息，就通过token去获取用户信息</span></span><br><span class="line">                getUserInfo(token).then(<span class="function"><span class="params">Response</span> =&gt;</span> &#123;</span><br><span class="line">                    <span class="keyword">const</span> resp = response.data</span><br><span class="line">                    <span class="keyword">if</span> (resp.flag) &#123;</span><br><span class="line">                        <span class="comment">// 获取到, 保存数据,则进行非登陆页面，否则回到登陆页面</span></span><br><span class="line">                        <span class="comment">//保存本地</span></span><br><span class="line">                        localStorage.setItem(<span class="string">'mgx-msm-user'</span>, <span class="built_in">JSON</span>.stringify(resp.data))</span><br><span class="line">                        next()</span><br><span class="line">                    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                        <span class="comment">// 未获取到,重新登录</span></span><br><span class="line">                        next(&#123; <span class="attr">path</span>: <span class="string">'/login'</span> &#125;)</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;)</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure></li>
<li>将权限添加 到main.js中<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 权限拦截</span></span><br><span class="line"><span class="keyword">import</span> <span class="string">'./permission'</span></span><br></pre></td></tr></table></figure>
</li>
</ol>
<hr>
<h2 id="会员模块"><a href="#会员模块" class="headerlink" title="会员模块"></a>会员模块</h2><h3 id="会员数据列表"><a href="#会员数据列表" class="headerlink" title="会员数据列表"></a>会员数据列表</h3><ul>
<li><p>EasyMock 添加数据列表模拟接口</p>
<blockquote>
<p>请求URL： /member/list<br>请求方式： get<br>描述：会员数据列表<br>mock.js 配置：</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line"><span class="string">"code"</span>: <span class="number">2000</span>,</span><br><span class="line"><span class="string">"flag"</span>: <span class="literal">true</span>,</span><br><span class="line"><span class="string">"message"</span>: <span class="string">"查询成功"</span>,</span><br><span class="line"><span class="string">"data|20"</span>: [&#123;</span><br><span class="line"><span class="string">"id|+1"</span>: <span class="number">10</span>,</span><br><span class="line"><span class="string">"cardNum"</span>: <span class="string">"@integer(10000)"</span>, <span class="comment">//大于1000的正整数</span></span><br><span class="line"><span class="string">"name"</span>: <span class="string">"@cname"</span>,</span><br><span class="line"><span class="string">"birthday"</span>: <span class="string">"@date"</span>,</span><br><span class="line"><span class="string">"phone|11"</span>: <span class="string">"@integer(0,9)"</span>, <span class="comment">// 11个数字0-9间的数字</span></span><br><span class="line"><span class="string">"integral"</span>: <span class="string">"@integer(0, 500)"</span>,</span><br><span class="line"><span class="string">"money"</span>: <span class="string">"@float(0, 1000, 1, 3)"</span>, <span class="comment">// 0-1000小数,1-3位小数位</span></span><br><span class="line"><span class="string">"payType|1"</span>: [<span class="string">'1'</span>,<span class="string">'2'</span>,<span class="string">'3'</span>,<span class="string">'4'</span>], <span class="comment">// 4选 其1</span></span><br><span class="line"><span class="string">"address"</span>: <span class="string">"@county(true)"</span></span><br><span class="line">&#125;]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
<li><p>Api调用接口</p>
<ol>
<li>在 src/api 下创建 member.js , 调用接口代码如下<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> request <span class="keyword">from</span> <span class="string">"@/utils/request"</span></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">default</span> &#123;</span><br><span class="line">    <span class="comment">// 获取会员列表</span></span><br><span class="line">    getList() &#123;</span><br><span class="line">        <span class="keyword">return</span> request(&#123;</span><br><span class="line">            url: <span class="string">'/member/list'</span>,</span><br><span class="line">            method: <span class="string">'get'</span></span><br><span class="line">        &#125;)</span><br><span class="line">    &#125;,</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
<li>在 src\views\member\index.vue 中, 添加 JS 代码如下：<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">&lt;script&gt;</span><br><span class="line"><span class="keyword">import</span> memberApi <span class="keyword">from</span> <span class="string">"@/api/member"</span>;</span><br><span class="line"><span class="keyword">export</span> <span class="keyword">default</span> &#123;</span><br><span class="line">  data() &#123;</span><br><span class="line">    <span class="keyword">return</span> &#123;</span><br><span class="line">      list: []</span><br><span class="line">    &#125;;</span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="comment">// 钩子函数获取数据</span></span><br><span class="line">  created() &#123;</span><br><span class="line">    <span class="keyword">this</span>.fetchData();</span><br><span class="line">  &#125;,</span><br><span class="line">  methods: &#123;</span><br><span class="line">    fetchData() &#123;</span><br><span class="line">      memberApi.getList().then(<span class="function"><span class="params">response</span> =&gt;</span> &#123;</span><br><span class="line">        <span class="keyword">this</span>.list = response.data.data;</span><br><span class="line">        <span class="built_in">console</span>.log(response.data)</span><br><span class="line">      &#125;);</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;;</span><br><span class="line">&lt;<span class="regexp">/script&gt;</span></span><br></pre></td></tr></table></figure></li>
</ol>
<ul>
<li>过滤器实现数据转换(1 2 3转换为微信，支付宝等)<br>渲染后发现支付类型是编号，应该将类型编号 转为名称。通过 filters 选项来定义过滤器来实现转换。<ul>
<li>member/index.js添加代码,JS 脚本处声明一个全局支付类型数组， 组件对象的 filters 选项指定转换规则<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br></pre></td><td class="code"><pre><span class="line">    &lt;script&gt;</span><br><span class="line">    <span class="keyword">import</span> memberApi <span class="keyword">from</span> <span class="string">"@/api/member"</span>;</span><br><span class="line"></span><br><span class="line">      <span class="comment">// 支付类型</span></span><br><span class="line">      <span class="keyword">const</span> payTypeOptions = [</span><br><span class="line">        &#123; <span class="attr">type</span>: <span class="string">"1"</span>, <span class="attr">name</span>: <span class="string">"现金"</span> &#125;,</span><br><span class="line">        &#123; <span class="attr">type</span>: <span class="string">"2"</span>, <span class="attr">name</span>: <span class="string">"微信"</span> &#125;,</span><br><span class="line">      &#123; <span class="attr">type</span>: <span class="string">"3"</span>, <span class="attr">name</span>: <span class="string">"支付宝"</span> &#125;,</span><br><span class="line">      &#123; <span class="attr">type</span>: <span class="string">"4"</span>, <span class="attr">name</span>: <span class="string">"银行卡"</span> &#125;</span><br><span class="line">    ];</span><br><span class="line"></span><br><span class="line">    <span class="keyword">export</span> <span class="keyword">default</span> &#123;</span><br><span class="line">      data() &#123;</span><br><span class="line">        <span class="keyword">return</span> &#123;</span><br><span class="line">          list: []</span><br><span class="line">        &#125;;</span><br><span class="line">      &#125;,</span><br><span class="line">      <span class="comment">// 钩子函数获取数据</span></span><br><span class="line">      created() &#123;</span><br><span class="line">        <span class="keyword">this</span>.fetchData();</span><br><span class="line">      &#125;,</span><br><span class="line">      methods: &#123;</span><br><span class="line">        fetchData() &#123;</span><br><span class="line">          memberApi.getList().then(<span class="function"><span class="params">response</span> =&gt;</span> &#123;</span><br><span class="line">            <span class="keyword">this</span>.list = response.data.data;</span><br><span class="line">            <span class="built_in">console</span>.log(response.data);</span><br><span class="line">          &#125;);</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;,</span><br><span class="line">      filters: &#123;</span><br><span class="line">        <span class="comment">// filters 中 this 指向的不是vue实例, 所有无法直接获取 data 中的数据</span></span><br><span class="line">        payTypeFilter(type) &#123;</span><br><span class="line">          <span class="comment">// 全局的 payTypeOptions , 返回一个满足条件的对象</span></span><br><span class="line">          <span class="keyword">const</span> obj = payTypeOptions.find(<span class="function"><span class="params">obj</span> =&gt;</span> obj.type === type);</span><br><span class="line">          <span class="comment">// 非空返回类型名称</span></span><br><span class="line">          <span class="keyword">return</span> obj ? obj.name : <span class="literal">null</span>;</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;;</span><br><span class="line">    &lt;<span class="regexp">/script&gt;</span></span><br><span class="line"><span class="regexp">    ~~~  </span></span><br><span class="line"><span class="regexp">+  修改 模板代码</span></span><br><span class="line"><span class="regexp">~~~js</span></span><br><span class="line"><span class="regexp"></span></span><br><span class="line"><span class="regexp">    &lt;el-table-column prop="payType" label="支付类型" &gt;</span></span><br><span class="line"><span class="regexp">    &lt;template slot-scope="scope"&gt;</span></span><br><span class="line"><span class="regexp">    &lt;span&gt;&#123;&#123; scope.row.payType | payTypeFilter &#125;&#125; &lt;/</span>span&gt;</span><br><span class="line">    &lt;<span class="regexp">/template&gt;</span></span><br><span class="line"><span class="regexp">    &lt;/</span>el-table-column&gt;</span><br></pre></td></tr></table></figure>
<h3 id="列表下方分页"><a href="#列表下方分页" class="headerlink" title="列表下方分页"></a>列表下方分页</h3></li>
</ul>
</li>
</ul>
</li>
<li><p>EasyMock 添加会员分页模拟接口</p>
<blockquote>
<p>请求URL： /member/list/search/{page}/{size}<br>page 当前要查询的页码， size 每页显示条数，通过这两个值，可查询出当前请求要响应的数据。<br>请求方式： post<br>描述：会员列表数据分页<br>mock.js 配置：</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  <span class="string">"code"</span>: <span class="number">2000</span>,</span><br><span class="line">  <span class="string">"flag"</span>: <span class="literal">true</span>,</span><br><span class="line">  <span class="string">"message"</span>: <span class="string">"查询成功"</span>,</span><br><span class="line">  <span class="string">"data"</span>: &#123;</span><br><span class="line">    <span class="string">"total"</span>: <span class="string">"@integer(100,200)"</span>, <span class="comment">// 查询出来的总记录数</span></span><br><span class="line">    <span class="string">"rows|10"</span>: [&#123; <span class="comment">// 返回当前页的记录数 10 条, 即每页显示 10 条记录</span></span><br><span class="line">      <span class="string">"id|+1"</span>: <span class="number">10</span>,</span><br><span class="line">      <span class="string">"cardNum"</span>: <span class="string">"@integer(10000)"</span>, <span class="comment">//大于1000的正整数</span></span><br><span class="line">      <span class="string">"name"</span>: <span class="string">"@cname"</span>,</span><br><span class="line">      <span class="string">"birthday"</span>: <span class="string">"@date"</span>,</span><br><span class="line">      <span class="string">"phone|11"</span>: <span class="string">"@integer(0,9)"</span>, <span class="comment">// 11个位数字</span></span><br><span class="line">      <span class="string">"integral"</span>: <span class="string">"@integer(0, 500)"</span>,</span><br><span class="line">      <span class="string">"money"</span>: <span class="string">"@float(0, 100, 1, 3)"</span>, <span class="comment">// 0-1000小数,1-3位小数位</span></span><br><span class="line">      <span class="string">"payType|1"</span>: [<span class="string">'1'</span>, <span class="string">'2'</span>, <span class="string">'3'</span>, <span class="string">'4'</span>],</span><br><span class="line">      <span class="string">"address"</span>: <span class="string">"@county(true)"</span></span><br><span class="line">    &#125;]</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
<li><p>Api调用接口</p>
<ol>
<li><p>修改 src\api 下的 member.js , 在导出的默认对象中，增加分页查询方法</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 分页查询,</span></span><br><span class="line"><span class="comment">// page当前页码, size 每页显示条数, searchMap 条件</span></span><br><span class="line"><span class="comment">// 后台要通过 page 和 size 统计本次请求响应的数据</span></span><br><span class="line">search(page, size, searchMap) &#123;</span><br><span class="line"><span class="keyword">return</span> request(&#123;</span><br><span class="line">url: <span class="string">`/member/list/search/<span class="subst">$&#123;page&#125;</span>/<span class="subst">$&#123;size&#125;</span>`</span>,</span><br><span class="line">method: <span class="string">'post'</span>,</span><br><span class="line">data: searchMap</span><br><span class="line">&#125;)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
<li><p>在 src\views\member\index.vue 中, 添加 JS 代码如下：<br>声明分页属性， 调用 getList 改为调用 search 方法</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">export</span> <span class="keyword">default</span> &#123;</span><br><span class="line">data() &#123;</span><br><span class="line">  <span class="keyword">return</span> &#123;</span><br><span class="line">    list: [],</span><br><span class="line">    total: <span class="number">0</span>, <span class="comment">// 总记录数</span></span><br><span class="line">    currentPage: <span class="number">1</span>, <span class="comment">// 当前页, 默认第1页</span></span><br><span class="line">    pageSize: <span class="number">10</span>, <span class="comment">// 每页显示条数， 10条</span></span><br><span class="line">    searchMap: &#123;&#125; <span class="comment">// 条件查询绑定条件值</span></span><br><span class="line">  &#125;;</span><br><span class="line">&#125;,</span><br><span class="line"><span class="comment">// 钩子函数获取数据</span></span><br><span class="line">created() &#123;</span><br><span class="line">  <span class="keyword">this</span>.fetchData();</span><br><span class="line">&#125;,</span><br><span class="line">methods: &#123;</span><br><span class="line">  fetchData() &#123;</span><br><span class="line">    <span class="comment">// memberApi.getList().then(response =&gt; &#123;</span></span><br><span class="line">    <span class="comment">//   this.list = response.data.data;</span></span><br><span class="line">    <span class="comment">//   console.log(response.data);</span></span><br><span class="line">    <span class="comment">// &#125;);</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">// 调用分页方法查询, 不要少了 this</span></span><br><span class="line">    memberApi</span><br><span class="line">      .search(<span class="keyword">this</span>.currentPage, <span class="keyword">this</span>.pageSize, <span class="keyword">this</span>.searchMap)</span><br><span class="line">      .then(<span class="function"><span class="params">response</span> =&gt;</span> &#123;</span><br><span class="line">        <span class="keyword">const</span> reqs = response.data;</span><br><span class="line">        <span class="keyword">this</span>.total = reqs.data.total;</span><br><span class="line">        <span class="keyword">this</span>.list = reqs.data.rows;</span><br><span class="line">        <span class="built_in">console</span>.log(<span class="keyword">this</span>.total, <span class="keyword">this</span>.list);</span><br><span class="line">      &#125;);</span><br><span class="line">  &#125;</span><br><span class="line">&#125;,</span><br></pre></td></tr></table></figure></li>
<li><p>添加分页模板</p>
<ul>
<li><p>修改 src\views\member\index.vue ， template 标签中添加页面模板代码：  </p>
<p>注意：添加在 div 里面。因为 template 里面只能有唯一根节点<br>current-change 和 size-change 事件都是调用 fetchData </p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">&lt;!-- 分页，添加在div里面 --&gt;</span><br><span class="line">&lt;el-pagination</span><br><span class="line">@size-change=<span class="string">"fetchData"</span></span><br><span class="line">@current-change=<span class="string">"fetchData"</span></span><br><span class="line">:current-page=<span class="string">"currentPage"</span></span><br><span class="line">:page-sizes=<span class="string">"[10, 20, 50]"</span></span><br><span class="line">:page-size=<span class="string">"pageSize"</span></span><br><span class="line">layout=<span class="string">"total, sizes, prev, pager, next, jumper"</span></span><br><span class="line">:total=<span class="string">"total"</span>&gt;</span><br><span class="line">&lt;<span class="regexp">/el-pagination&gt;</span></span><br></pre></td></tr></table></figure></li>
</ul>
</li>
<li><p>解决动态页码和当前页</p>
<ul>
<li>将 @size-change 和 @current-change 事件处理的函数名改变为 handleSizeChange 和<br>handleCurrentChange<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">&lt;el-pagination</span><br><span class="line">@size-change=<span class="string">"handleSizeChange"</span></span><br><span class="line">@current-change=<span class="string">"handleCurrentChange"</span></span><br></pre></td></tr></table></figure></li>
<li>在 methods 中添加函数，<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">  methods: &#123;</span><br><span class="line">handleSizeChange(val) &#123;</span><br><span class="line"><span class="keyword">this</span>.pageSize = val</span><br><span class="line"><span class="keyword">this</span>.fetchData()</span><br><span class="line">&#125;,</span><br><span class="line">handleCurrentChange(val) &#123;</span><br><span class="line"><span class="keyword">this</span>.currentPage = val</span><br><span class="line"><span class="keyword">this</span>.fetchData()</span><br><span class="line">&#125;,</span><br></pre></td></tr></table></figure>
<h3 id="条件查询实现"><a href="#条件查询实现" class="headerlink" title="条件查询实现"></a>条件查询实现</h3></li>
</ul>
</li>
</ol>
</li>
<li><p>修改 src\views\member\index.vue ，增加条件查询模板代码：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line">&lt;!-- 条件查询。 inline 属性设置表单变为行内的表单域 --&gt;</span><br><span class="line">&lt;el-form ref=<span class="string">"searchForm"</span> :inline=<span class="string">"true"</span> :model=<span class="string">"searchMap"</span> style=<span class="string">"margin-top: 20px;"</span> &gt;</span><br><span class="line">&lt;!-- 有prop才可以重置 --&gt;</span><br><span class="line">&lt;el-form-item prop=<span class="string">"cardNum"</span>&gt;</span><br><span class="line">&lt;el-input v-model=<span class="string">"searchMap.cardNum"</span> placeholder=<span class="string">"会员卡号"</span> style=<span class="string">"width: 200px;"</span> &gt;<span class="xml"><span class="tag">&lt;/<span class="name">el-input</span>&gt;</span></span></span><br><span class="line">&lt;<span class="regexp">/el-form-item&gt;</span></span><br><span class="line"><span class="regexp">&lt;el-form-item prop="name"&gt;</span></span><br><span class="line"><span class="regexp">&lt;el-input v-model="searchMap.name" placeholder="会员名称" style="width: 200px;" &gt;&lt;/</span>el-input&gt;</span><br><span class="line">&lt;<span class="regexp">/el-form-item&gt;</span></span><br><span class="line"><span class="regexp">&lt;el-form-item prop="payType"&gt;</span></span><br><span class="line"><span class="regexp">&lt;el-select v-model="searchMap.payType" placeholder="支付类型" style="width: 110px" &gt;</span></span><br><span class="line"><span class="regexp">&lt;!--key 标识， label 下拉显示的文本，vulue 表单值 --&gt;</span></span><br><span class="line"><span class="regexp">&lt;el-option</span></span><br><span class="line"><span class="regexp">v-for="option in payTypeOptions"</span></span><br><span class="line"><span class="regexp">:key="option.type"</span></span><br><span class="line"><span class="regexp">:label="option.name"</span></span><br><span class="line"><span class="regexp">:value="option.type"</span></span><br><span class="line"><span class="regexp">/</span>&gt;</span><br><span class="line">&lt;<span class="regexp">/el-select&gt;</span></span><br><span class="line"><span class="regexp">&lt;/</span>el-form-item&gt;</span><br><span class="line">&lt;el-form-item prop=<span class="string">"birthday"</span>&gt;</span><br><span class="line">&lt;!-- value-format 是指定绑定值的格式 --&gt;</span><br><span class="line">&lt;el-date-picker value-format=<span class="string">"yyyy-MM-dd"</span> v-model=<span class="string">"searchMap.birthday"</span> type=<span class="string">"date"</span> placeholder=<span class="string">"出生日期"</span>&gt;<span class="xml"><span class="tag">&lt;/<span class="name">el-date-picker</span>&gt;</span></span></span><br><span class="line">&lt;<span class="regexp">/el-form-item&gt;</span></span><br><span class="line"><span class="regexp">&lt;el-form-item&gt;</span></span><br><span class="line"><span class="regexp">&lt;el-button type="primary" icon="el-icon-search" @click="fetchData"&gt;查询&lt;/</span>el-button&gt;</span><br><span class="line">&lt;<span class="regexp">/el-form-item&gt;</span></span><br><span class="line"><span class="regexp">&lt;/</span>el-form&gt;</span><br></pre></td></tr></table></figure></li>
<li><p>在 data 选项声明 payTypeOptions 属性用于下拉框 ,并将全局的赋值给它</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">data() &#123;</span><br><span class="line"><span class="keyword">return</span> &#123;</span><br><span class="line">  list: [],</span><br><span class="line">  total: <span class="number">0</span>, <span class="comment">// 总记录数</span></span><br><span class="line">  currentPage: <span class="number">1</span>, <span class="comment">// 当前页, 默认第1页</span></span><br><span class="line">  pageSize: <span class="number">10</span>, <span class="comment">// 每页显示条数， 10条</span></span><br><span class="line">  searchMap: &#123; <span class="comment">// 条件查询绑定的条件值</span></span><br><span class="line">  cardNum: <span class="string">''</span>,</span><br><span class="line">  name: <span class="string">''</span>,</span><br><span class="line">  payType: <span class="string">''</span>,</span><br><span class="line">  birthday: <span class="string">''</span></span><br><span class="line">  &#125;,</span><br><span class="line">  payTypeOptions, <span class="comment">// 支付类型，ES6语法</span></span><br><span class="line">  &#125;</span><br><span class="line">  &#125;,</span><br></pre></td></tr></table></figure></li>
<li><h3 id="搜索框重置功能"><a href="#搜索框重置功能" class="headerlink" title="搜索框重置功能"></a>搜索框重置功能</h3></li>
<li><p>在 条件查询区域添加 一个 重置 按钮</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&lt;el-button @click=<span class="string">"resetForm('searchForm')"</span>&gt;重置&lt;<span class="regexp">/el-button&gt;</span></span><br></pre></td></tr></table></figure></li>
<li><p>methods 选项中添加重置处理方法 resetForm<br>  注意: 在 el-form-item 标签属性 prop 上, 指定了字段名, 重置才会生效</p>
  <figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 表单重置，</span></span><br><span class="line">    <span class="comment">// 在 el-form-item 标签属性 prop 上, 指定了字段名, 重置才会生效</span></span><br><span class="line">    resetForm(formName) &#123;</span><br><span class="line">      <span class="keyword">this</span>.$refs[formName].resetFields();</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>
<h3 id="新增会员对话框"><a href="#新增会员对话框" class="headerlink" title="新增会员对话框"></a>新增会员对话框</h3><ol>
<li><p>在 src\views\member\index.vue 中分页区域的下方，新增对话框形式表单数据模板</p>
<ul>
<li>el-dialog 标答属性 title 窗口标题，visible.sync 是否弹出窗口<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">&lt;el-dialog title=<span class="string">"会员编辑"</span> :visible.sync=<span class="string">"dialogFormVisible"</span> width=<span class="string">"500px"</span>&gt;</span><br><span class="line">&lt;!-- status-icon 当表单校验不通过时, 输入框右侧有个 x 小图标 --&gt;</span><br><span class="line">  &lt;el-form</span><br><span class="line">    status-icon</span><br><span class="line">    ref=<span class="string">"pojoForm"</span></span><br><span class="line">    :model=<span class="string">"pojo"</span></span><br><span class="line">    label-width=<span class="string">"100px"</span></span><br><span class="line">    label-position=<span class="string">"right"</span></span><br><span class="line">    style=<span class="string">"width: 400px;"</span></span><br><span class="line">  &gt;</span><br><span class="line">    &lt;el-form-item label=<span class="string">"会员卡号"</span> prop=<span class="string">"cardNum"</span>&gt;</span><br><span class="line">      &lt;el-input v-model=<span class="string">"pojo.cardNum"</span> /&gt;</span><br><span class="line">    &lt;<span class="regexp">/el-form-item&gt;</span></span><br><span class="line"><span class="regexp">    &lt;el-form-item label="会员姓名" prop="name"&gt;</span></span><br><span class="line"><span class="regexp">      &lt;el-input v-model="pojo.name" /</span>&gt;</span><br><span class="line">    &lt;<span class="regexp">/el-form-item&gt;</span></span><br><span class="line"><span class="regexp">    &lt;el-form-item label="会员生日" prop="birthday"&gt;</span></span><br><span class="line"><span class="regexp">      &lt;el-date-picker v-model="pojo.birthday" type="date" placeholder="请点击选择" /</span>&gt;</span><br><span class="line">    &lt;<span class="regexp">/el-form-item&gt;</span></span><br><span class="line"><span class="regexp">    &lt;el-form-item label="手机号码" prop="phone"&gt;</span></span><br><span class="line"><span class="regexp">      &lt;el-input v-model="pojo.phone" /</span>&gt;</span><br><span class="line">    &lt;<span class="regexp">/el-form-item&gt;</span></span><br><span class="line"><span class="regexp">    &lt;el-form-item label="开卡金额" prop="money"&gt;</span></span><br><span class="line"><span class="regexp">      &lt;el-input v-model="pojo.money" /</span>&gt;</span><br><span class="line">    &lt;<span class="regexp">/el-form-item&gt;</span></span><br><span class="line"><span class="regexp">    &lt;el-form-item label="可用积分"&gt;</span></span><br><span class="line"><span class="regexp">      &lt;el-input v-model="pojo.integral"&gt;&lt;/</span>el-input&gt;</span><br><span class="line">    &lt;<span class="regexp">/el-form-item&gt;</span></span><br><span class="line"><span class="regexp">    &lt;el-form-item label="支付类型" prop="payType"&gt;</span></span><br><span class="line"><span class="regexp">      &lt;el-select v-model="pojo.payType" class="filter-item" placeholder="请点击选择"&gt;</span></span><br><span class="line"><span class="regexp">        &lt;el-option</span></span><br><span class="line"><span class="regexp">          v-for="option in payTypeOptions"</span></span><br><span class="line"><span class="regexp">          :key="option.type"</span></span><br><span class="line"><span class="regexp">          :label="option.name"</span></span><br><span class="line"><span class="regexp">          :value="option.type"</span></span><br><span class="line"><span class="regexp">        /</span>&gt;</span><br><span class="line">      &lt;<span class="regexp">/el-select&gt;</span></span><br><span class="line"><span class="regexp">    &lt;/</span>el-form-item&gt;</span><br><span class="line">    &lt;el-form-item label=<span class="string">"会员地址"</span>&gt;</span><br><span class="line">      &lt;el-input</span><br><span class="line">        v-model=<span class="string">"pojo.address"</span></span><br><span class="line">        type=<span class="string">"textarea"</span></span><br><span class="line">        :autosize=<span class="string">"&#123; minRows: 2, maxRows: 4&#125;"</span></span><br><span class="line">        placeholder=<span class="string">"请输入地址"</span></span><br><span class="line">      /&gt;</span><br><span class="line">    &lt;<span class="regexp">/el-form-item&gt;</span></span><br><span class="line"><span class="regexp">  &lt;/</span>el-form&gt;</span><br><span class="line">  &lt;div slot=<span class="string">"footer"</span> <span class="class"><span class="keyword">class</span></span>=<span class="string">"dialog-footer"</span>&gt;</span><br><span class="line">    &lt;el-button @click=<span class="string">"dialogFormVisible = false"</span>&gt;取 消&lt;<span class="regexp">/el-button&gt;</span></span><br><span class="line"><span class="regexp">    &lt;el-button type="primary" @click="addData('pojoForm')"&gt;确 定&lt;/</span>el-button&gt;</span><br><span class="line">  &lt;<span class="regexp">/div&gt;</span></span><br><span class="line"><span class="regexp">&lt;/</span>el-dialog&gt;</span><br></pre></td></tr></table></figure></li>
</ul>
</li>
<li><p>data 选项中声明变量数据对象 pojo 和 dialogFormVisible 当它为 true 弹出，false 不弹。</p>
 <figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">pojo: &#123;</span><br><span class="line">cardNum: <span class="string">''</span>,</span><br><span class="line">name: <span class="string">''</span>,</span><br><span class="line">birthday: <span class="string">''</span>,</span><br><span class="line">phone: <span class="string">''</span>,</span><br><span class="line">money: <span class="number">0</span>,</span><br><span class="line">integral: <span class="number">0</span>,</span><br><span class="line">payType: <span class="string">''</span>,</span><br><span class="line">address: <span class="string">''</span></span><br><span class="line">&#125;, <span class="comment">// 提交的数据</span></span><br><span class="line">dialogFormVisible: <span class="literal">false</span>, <span class="comment">// 控制新增对话框</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
<li><p>在 methods 中添加 addData() 函数,提交表单数据用的</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">  <span class="comment">// 提交新增数据</span></span><br><span class="line">addData(formName) &#123;</span><br><span class="line"><span class="keyword">this</span>.$refs[formName].validate(<span class="function"><span class="params">valid</span> =&gt;</span> &#123;</span><br><span class="line"><span class="keyword">if</span> (valid) &#123;</span><br><span class="line"><span class="comment">// 验证通过，提交添加</span></span><br><span class="line">alert(<span class="string">'Add submit!'</span>);</span><br><span class="line">&#125; <span class="keyword">else</span> &#123;</span><br><span class="line"><span class="comment">// 验证不通过</span></span><br><span class="line"><span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">&#125;</span><br><span class="line">&#125;)</span><br><span class="line">&#125;,</span><br></pre></td></tr></table></figure></li>
<li><p>在 template 中的查询按钮旁边添加一个 新增 按钮，用于打开新增会员对话框</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">&lt;el-button type=<span class="string">"primary"</span> icon=<span class="string">"el-icon-edit"</span></span><br><span class="line">@click=<span class="string">"handleAdd"</span>&gt;新增&lt;<span class="regexp">/el-button&gt;</span></span><br></pre></td></tr></table></figure></li>
<li><p>在 methods 中添加 handleAdd() 函数, 打开新增对话框</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 打开新增窗口</span></span><br><span class="line">    handleAdd() &#123;</span><br><span class="line">      <span class="keyword">this</span>.dialogFormVisible = <span class="literal">true</span></span><br><span class="line">        <span class="keyword">this</span>.$nextTick(<span class="function"><span class="params">()</span> =&gt;</span> &#123;</span><br><span class="line">        <span class="comment">// this.$nextTick()它是一个异步事件，当渲染结束 之后 ，它的回调函数才会被执行</span></span><br><span class="line">        <span class="comment">// 弹出窗口打开之后 ，需要加载Dom, 就需要花费一点时间，我们就应该等待它加载完dom之后，再进行调</span></span><br><span class="line">        用resetFields方法，重置表单和清除样式</span><br><span class="line">        <span class="keyword">this</span>.$refs[<span class="string">'pojoForm'</span>].resetFields()</span><br><span class="line">      &#125;)</span><br><span class="line">    &#125;,</span><br></pre></td></tr></table></figure></li>
<li><p>表单数据校验</p>
<ul>
<li>在新增窗口的 el-form 上绑定属性 :rules=”rules”</li>
<li>在 data 选项中添加 rules 属性进行校验，对卡号，姓名、支付类型 校验<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">data() &#123;</span><br><span class="line"><span class="keyword">return</span> &#123;</span><br><span class="line">。。。</span><br><span class="line"><span class="comment">// 校验规则</span></span><br><span class="line">rules: &#123;</span><br><span class="line">cardNum: [&#123; <span class="attr">required</span>: <span class="literal">true</span>, <span class="attr">message</span>: <span class="string">'卡号不能为空'</span>, <span class="attr">trigger</span>: <span class="string">'blur'</span> &#125;],</span><br><span class="line">name: [&#123; <span class="attr">required</span>: <span class="literal">true</span>, <span class="attr">message</span>: <span class="string">'姓名不能为空'</span>, <span class="attr">trigger</span>: <span class="string">'blur'</span> &#125;],</span><br><span class="line">payType: [&#123; <span class="attr">required</span>: <span class="literal">true</span>, <span class="attr">message</span>: <span class="string">'请选择支付类型'</span>, <span class="attr">trigger</span>: <span class="string">'change'</span> &#125;],</span><br><span class="line">&#125;,</span><br><span class="line">&#125;</span><br><span class="line">&#125;,</span><br></pre></td></tr></table></figure>
</li>
</ul>
</li>
<li><p>表单数据提交</p>
<ul>
<li>EasyMock 添加新增会员模拟接口<blockquote>
<p>请求URL： /member<br>请求方式： post<br>描述：新增会员<br>mock.js 配置：</p>
</blockquote>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line"> &quot;code&quot;: 2000,</span><br><span class="line"> &quot;flag&quot;: true,</span><br><span class="line"> &#39;message&#39;: &quot;新增成功&quot;</span><br><span class="line"> &#125;</span><br></pre></td></tr></table></figure></li>
<li>Api 调用接口<ol>
<li>src\api\member.js 导出的默认对象中，添加调用新增接口的方法<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 新增会员</span></span><br><span class="line">add(pojo) &#123;</span><br><span class="line"><span class="keyword">return</span> request(&#123;</span><br><span class="line">url: <span class="string">'/member'</span>,</span><br><span class="line">method: <span class="string">'post'</span>,</span><br><span class="line">data: pojo</span><br><span class="line">&#125;)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
<li>在 src\views\member\index.vue 中的 addData 方法中提交数据，代码如下：<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"> <span class="comment">// 提交新增数据</span></span><br><span class="line">addData(formName) &#123;</span><br><span class="line"><span class="keyword">this</span>.$refs[formName].validate(<span class="function"><span class="params">valid</span> =&gt;</span> &#123;</span><br><span class="line"><span class="keyword">if</span> (valid) &#123;</span><br><span class="line"><span class="comment">// 验证通过，提交添加</span></span><br><span class="line">memberApi.add(<span class="keyword">this</span>.pojo).then(<span class="function"><span class="params">response</span> =&gt;</span> &#123;</span><br><span class="line"><span class="keyword">const</span> resp = response.data</span><br><span class="line"><span class="built_in">console</span>.log(resp)</span><br><span class="line"><span class="keyword">if</span> (resp.flag) &#123;</span><br><span class="line"><span class="comment">// 新增成功, 刷新列表数据</span></span><br><span class="line"><span class="keyword">this</span>.fetchData()</span><br><span class="line"><span class="keyword">this</span>.dialogFormVisible=<span class="literal">false</span> <span class="comment">//关闭窗口</span></span><br><span class="line">&#125;<span class="keyword">else</span> &#123;</span><br><span class="line"><span class="comment">// 失败, 弹出提示</span></span><br><span class="line"><span class="keyword">this</span>.$message(&#123;</span><br><span class="line">  message: resp.message,</span><br><span class="line">  type: <span class="string">'warning'</span></span><br><span class="line">  &#125;);</span><br><span class="line">  &#125;</span><br><span class="line">  &#125;)</span><br><span class="line">  &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">  <span class="comment">// 验证不通过</span></span><br><span class="line">  <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">  &#125;</span><br><span class="line">  &#125;)</span><br><span class="line">  &#125;,</span><br></pre></td></tr></table></figure>
<h3 id="会员信息修改"><a href="#会员信息修改" class="headerlink" title="会员信息修改"></a>会员信息修改</h3></li>
</ol>
</li>
</ul>
</li>
</ol>
<ul>
<li><p>EasyMock 添加模拟接口</p>
<ol>
<li>ID 查询数据接口<blockquote>
<p>请求URL： /member/{id}<br>请求方式： get<br>描述：会员 ID 查询数据接口<br>mock.js 配置：</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  <span class="string">"code"</span>: <span class="number">2000</span>,</span><br><span class="line">  <span class="string">"flag"</span>: <span class="literal">true</span>,</span><br><span class="line">  <span class="string">"message"</span>: <span class="string">"查询成功"</span>,</span><br><span class="line">  <span class="string">"data"</span>: &#123;</span><br><span class="line">  <span class="string">"id"</span>: <span class="number">10</span>,</span><br><span class="line">  <span class="string">"cardNum"</span>: <span class="string">"test01"</span>, <span class="comment">//大于1000的正整数</span></span><br><span class="line">  <span class="string">"name"</span>: <span class="string">"测试会员"</span>,</span><br><span class="line">  <span class="string">"birthday"</span>: <span class="string">"@date"</span>,</span><br><span class="line">  <span class="string">"phone|11"</span>: <span class="string">"@integer(0,9)"</span>, <span class="comment">// 11个位数字</span></span><br><span class="line">  <span class="string">"integral"</span>: <span class="string">"@integer(0, 500)"</span>,</span><br><span class="line">  <span class="string">"money"</span>: <span class="string">"@float(0, 100, 1, 3)"</span>, <span class="comment">// 0-1000小数,1-3位小数位</span></span><br><span class="line">  <span class="string">"payType|1"</span>: [<span class="string">'1'</span>, <span class="string">'2'</span>, <span class="string">'3'</span>, <span class="string">'4'</span>],</span><br><span class="line">  <span class="string">"address"</span>: <span class="string">"@county(true)"</span></span><br><span class="line">  &#125;</span><br><span class="line">  &#125;</span><br></pre></td></tr></table></figure></li>
<li>提交修改数据接口<blockquote>
<p>请求URL： /member/{id}<br>说明：id 是修改的那条数据<br>请求方式： put<br>描述：会员数据更新<br>mock.js 配置</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  <span class="string">"code"</span>: <span class="number">2000</span>,</span><br><span class="line">  <span class="string">"flag"</span>: <span class="literal">true</span>,</span><br><span class="line">  <span class="string">'message'</span>: <span class="string">"修改成功"</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
</ol>
</li>
<li><p>Api 调用接口</p>
<ol>
<li>src\api\member.js 导出的默认对象中，添加ID查询方法 getById 和 更新方法 update<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 查询</span></span><br><span class="line">  getById(id) &#123;</span><br><span class="line">  <span class="keyword">return</span> request(&#123;</span><br><span class="line">    url: <span class="string">`/member/<span class="subst">$&#123;id&#125;</span>`</span>, <span class="comment">// 反单引号 `</span></span><br><span class="line">    method: <span class="string">'get'</span></span><br><span class="line">    &#125;)</span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="comment">// 更新</span></span><br><span class="line">  update(pojo) &#123;</span><br><span class="line">  <span class="keyword">return</span> request(&#123;</span><br><span class="line">      url: <span class="string">`/member/<span class="subst">$&#123;pojo.id&#125;</span>`</span>, <span class="comment">// 反单引号 ``</span></span><br><span class="line">      method: <span class="string">'put'</span>, <span class="comment">// put 方式提交</span></span><br><span class="line">      data: pojo</span><br><span class="line">    &#125;)</span><br><span class="line">  &#125;</span><br></pre></td></tr></table></figure></li>
<li>在 src\views\member\index.vue 中的 handleEdit 方法做如下修改：<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 打开编辑窗口</span></span><br><span class="line">  handleEdit(id) &#123;</span><br><span class="line">    <span class="comment">// 清空原数据</span></span><br><span class="line">    <span class="keyword">this</span>.handleAdd()</span><br><span class="line">    <span class="comment">// 通过Id查询数据</span></span><br><span class="line">    memberApi.getById(id).then(<span class="function"><span class="params">response</span> =&gt;</span> &#123;</span><br><span class="line">      <span class="keyword">const</span> resp = response.data</span><br><span class="line">      <span class="keyword">if</span>(resp.flag) &#123;</span><br><span class="line">      <span class="keyword">this</span>.pojo = resp.data</span><br><span class="line">     &#125;</span><br><span class="line">    &#125;)</span><br><span class="line">  &#125;,</span><br></pre></td></tr></table></figure></li>
<li>在 data选项的 pojo 对象中添加 id 属性<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">id: null, &#x2F;&#x2F;增加id</span><br></pre></td></tr></table></figure></li>
<li>修改对话框中的确认按钮点击事件， pojo.id === null 值为true是新增，有id说明是更新\<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">&lt;el-button type=<span class="string">"primary"</span> @click=<span class="string">"pojo.id === null ? addData('pojoForm'): updateData('pojoForm')"</span>&gt;确 定</span><br><span class="line"> &lt;<span class="regexp">/el-button&gt;</span></span><br></pre></td></tr></table></figure></li>
<li>提交更新数据<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"> updateData(formName) &#123;</span><br><span class="line">  <span class="keyword">this</span>.$refs[formName].validate(<span class="function"><span class="params">valid</span> =&gt;</span> &#123;</span><br><span class="line">    <span class="keyword">if</span> (valid) &#123;</span><br><span class="line">      <span class="comment">// 验证通过，提交</span></span><br><span class="line">      memberApi.update(<span class="keyword">this</span>.pojo).then(<span class="function"><span class="params">response</span> =&gt;</span> &#123;</span><br><span class="line">        <span class="keyword">const</span> resp = response.data;</span><br><span class="line">        <span class="keyword">if</span> (resp.flag) &#123;</span><br><span class="line">          <span class="keyword">this</span>.fetchData(); <span class="comment">// 刷新列表数据</span></span><br><span class="line">          <span class="keyword">this</span>.dialogFormVisible = <span class="literal">false</span>; <span class="comment">// 关闭窗口</span></span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">          <span class="comment">// 失败, 弹出提示</span></span><br><span class="line">          <span class="keyword">this</span>.$message(&#123;</span><br><span class="line">            message: resp.message,</span><br><span class="line">            type: <span class="string">"warning"</span></span><br><span class="line">          &#125;);</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;);</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">      <span class="comment">// 验证不通过</span></span><br><span class="line">      <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="会员信息删除"><a href="#会员信息删除" class="headerlink" title="会员信息删除"></a>会员信息删除</h3></li>
</ol>
</li>
<li><p>EasyMock 添加模拟接口</p>
<blockquote>
<p>请求URL： /member/{id}<br>请求方式： delete<br>描述：根据会员ID删除<br>mock.js 配置：</p>
 <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">&quot;code&quot;: 2000,</span><br><span class="line">&quot;flag&quot;: true,</span><br><span class="line">&quot;message&quot;: &quot;删除成功&quot;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></blockquote>
</li>
<li><p>api调用接口</p>
<ol>
<li>src\api\member.js 导出的默认对象中，添加 deleteById 方法<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">deleteById(id) &#123;</span><br><span class="line">  <span class="keyword">return</span> request(&#123;</span><br><span class="line">    url: <span class="string">`/member/<span class="subst">$&#123;id&#125;</span>`</span>, <span class="comment">// 反单引号 ``</span></span><br><span class="line">    method: <span class="string">'delete'</span>, <span class="comment">// delete 方式提交</span></span><br><span class="line">  &#125;)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
<li>在 src\views\member\index.vue 中的 handleDele 方法做如下修改：<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//删除操作</span></span><br><span class="line">    handleDele(id) &#123;</span><br><span class="line">      <span class="built_in">console</span>.log(<span class="string">"删除"</span>, id);</span><br><span class="line">      <span class="keyword">this</span>.$confirm(<span class="string">"确认删除这条记录吗？"</span>, <span class="string">"提示"</span>, &#123;</span><br><span class="line">        confirmButtonText: <span class="string">"确定"</span>,</span><br><span class="line">        cancelButtonText: <span class="string">"取消"</span>,</span><br><span class="line">        type: <span class="string">"warning"</span></span><br><span class="line">      &#125;).then(<span class="function"><span class="params">()</span> =&gt;</span> &#123;</span><br><span class="line">          <span class="comment">// 确认</span></span><br><span class="line">          <span class="built_in">console</span>.log(<span class="string">'确认'</span>)</span><br><span class="line">          memberApi.deleteById(id).then(<span class="function"><span class="params">response</span> =&gt;</span> &#123;</span><br><span class="line">            <span class="keyword">const</span> resp = response.data;</span><br><span class="line">            <span class="comment">//提示信息</span></span><br><span class="line">            <span class="keyword">this</span>.$message(&#123;</span><br><span class="line">              message: resp.message,</span><br><span class="line">              type: resp.flag ? <span class="string">'success'</span>: <span class="string">'error'</span></span><br><span class="line">            &#125;)</span><br><span class="line">            <span class="keyword">if</span> (resp.flag) &#123;</span><br><span class="line">              <span class="comment">// 删除成功，刷新列表</span></span><br><span class="line">              <span class="keyword">this</span>.fetchData();</span><br><span class="line">            &#125;</span><br><span class="line">          &#125;);</span><br><span class="line">        &#125;).catch(<span class="function"><span class="params">()</span> =&gt;</span> &#123;</span><br><span class="line">          <span class="comment">// 取消删除，不理会</span></span><br><span class="line">          <span class="built_in">console</span>.log(<span class="string">'取消'</span>)</span><br><span class="line">        &#125;);</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>
</li>
</ol>
</li>
</ul>
</li>
</ul>

      
    </div>
    
    
    

    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>要恰饭的嘛</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/images/vx.jpg" alt="alexhigger 微信支付"/>
        <p>微信支付</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/images/alibaba.jpg" alt="alexhigger 支付宝"/>
        <p>支付宝</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/%E5%89%8D%E7%AB%AF/" rel="tag"><i class="fa fa-envira"></i>前端</a>
          
            <a href="/tags/js/" rel="tag"><i class="fa fa-envira"></i>js</a>
          
            <a href="/tags/vue/" rel="tag"><i class="fa fa-envira"></i>vue</a>
          
            <a href="/tags/%E9%A1%B9%E7%9B%AE/" rel="tag"><i class="fa fa-envira"></i>项目</a>
          
            <a href="/tags/axios/" rel="tag"><i class="fa fa-envira"></i>axios</a>
          
            <a href="/tags/ElementUI/" rel="tag"><i class="fa fa-envira"></i>ElementUI</a>
          
            <a href="/tags/Mock-js/" rel="tag"><i class="fa fa-envira"></i>Mock.js</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2020/01/31/msm/msm%E4%BC%9A%E5%91%98%E7%B3%BB%E7%BB%9F%E9%A1%B9%E7%9B%AE%E6%90%AD%E5%BB%BA%E9%98%B6%E6%AE%B5/" rel="next" title="msm会员系统项目搭建阶段">
                <i class="fa fa-chevron-left"></i> msm会员系统项目搭建阶段
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2020/02/06/msm/msm%E4%BC%9A%E5%91%98%E7%B3%BB%E7%BB%9F---%E4%BE%9B%E5%BA%94%E5%95%86%E6%A8%A1%E5%9D%97/" rel="prev" title="msm会员系统登录----供应商管理模块">
                msm会员系统登录----供应商管理模块 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
    </div>
  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/images/icon.jpg"
                alt="alexhigger" />
            
              <p class="site-author-name" itemprop="name">alexhigger</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives">
              
                  <span class="site-state-item-count">29</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">27</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          
            <div class="feed-link motion-element">
              <a href="/atom.xml" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
            </div>
          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/alexhigger" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="773821742@qq.com" target="_blank" title="E-Mail">
                      
                        <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="773821742" target="_blank" title="QQ">
                      
                        <i class="fa fa-fw fa-qq"></i>QQ</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="invincible3ai" target="_blank" title="WeChat">
                      
                        <i class="fa fa-fw fa-wechat"></i>WeChat</a>
                  </span>
                
            </div>
          

          
                    <iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width=330 height=86 src="//music.163.com/outchain/player?type=2&id=520458166&auto=1&height=66"></iframe>
             


          
          

          
          

          <!-- CloudCalendar -->
          <div class="widget-wrap" style="width: 90%;margin-left: auto;margin-right: auto; opacity: 0.97;">
            <div class="widget" id="CloudCalendar"></div>
          </div>

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#正式开发msm阶段"><span class="nav-number">1.</span> <span class="nav-text">正式开发msm阶段</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#登录页面"><span class="nav-number">1.1.</span> <span class="nav-text">登录页面</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#配置路由"><span class="nav-number">1.1.1.</span> <span class="nav-text">配置路由</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#表单"><span class="nav-number">1.1.2.</span> <span class="nav-text">表单</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#项目布局"><span class="nav-number">1.2.</span> <span class="nav-text">项目布局</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#配置路由-1"><span class="nav-number">1.2.1.</span> <span class="nav-text">配置路由</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#布局实现"><span class="nav-number">1.2.2.</span> <span class="nav-text">布局实现</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#头部区域实现"><span class="nav-number">1.2.3.</span> <span class="nav-text">头部区域实现</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#左侧导航实现"><span class="nav-number">1.2.4.</span> <span class="nav-text">左侧导航实现</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#右侧主区域实现"><span class="nav-number">1.2.5.</span> <span class="nav-text">右侧主区域实现</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#退出功能"><span class="nav-number">1.3.</span> <span class="nav-text">退出功能</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#权限验证"><span class="nav-number">1.4.</span> <span class="nav-text">权限验证</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#会员模块"><span class="nav-number">1.5.</span> <span class="nav-text">会员模块</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#会员数据列表"><span class="nav-number">1.5.1.</span> <span class="nav-text">会员数据列表</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#列表下方分页"><span class="nav-number">1.5.2.</span> <span class="nav-text">列表下方分页</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#条件查询实现"><span class="nav-number">1.5.3.</span> <span class="nav-text">条件查询实现</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#搜索框重置功能"><span class="nav-number">1.5.4.</span> <span class="nav-text">搜索框重置功能</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#新增会员对话框"><span class="nav-number">1.5.5.</span> <span class="nav-text">新增会员对话框</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#会员信息修改"><span class="nav-number">1.5.6.</span> <span class="nav-text">会员信息修改</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#会员信息删除"><span class="nav-number">1.5.7.</span> <span class="nav-text">会员信息删除</span></a></li></ol></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      
        <div class="back-to-top">
          <i class="fa fa-arrow-up"></i>
          
            <span id="scrollpercent"><span>0</span>%</span>
          
        </div>
      

     
<script type="text/javascript" charset="utf-8" src="/js/tagcloud.js"></script>
<script type="text/javascript" charset="utf-8" src="/js/tagcanvas.js"></script>
<div class="widget-wrap">
    <h3 class="widget-title">Tag Cloud</h3>
    <div id="myCanvasContainer" class="widget tagcloud">
        <canvas width="250" height="250" id="resCanvas" style="width=100%">
            <ul class="tag-list" itemprop="keywords"><li class="tag-list-item"><a class="tag-list-link" href="/tags/ElementUI/" rel="tag">ElementUI</a><span class="tag-list-count">6</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/FastDFS/" rel="tag">FastDFS</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Mock-js/" rel="tag">Mock.js</a><span class="tag-list-count">6</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/axios/" rel="tag">axios</a><span class="tag-list-count">6</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/bootstrap/" rel="tag">bootstrap</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/bug/" rel="tag">bug</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/easycode%EF%BC%8C%E6%B5%81%E7%A8%8B%EF%BC%8C%E6%8F%92%E4%BB%B6/" rel="tag">easycode，流程，插件</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/github/" rel="tag">github</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/java/" rel="tag">java</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/js/" rel="tag">js</a><span class="tag-list-count">12</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mybatis-plus/" rel="tag">mybatis-plus</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/restful/" rel="tag">restful</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/springboot/" rel="tag">springboot</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/swagger/" rel="tag">swagger</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/vue/" rel="tag">vue</a><span class="tag-list-count">13</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/vuex/" rel="tag">vuex</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/vue%EF%BC%8Cbootstrap/" rel="tag">vue，bootstrap</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%89%8D%E5%90%8E%E7%AB%AF%E5%88%86%E7%A6%BB/" rel="tag">前后端分离</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%89%8D%E7%AB%AF/" rel="tag">前端</a><span class="tag-list-count">12</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%8D%9A%E5%AE%A2%E6%90%AD%E5%BB%BA/" rel="tag">博客搭建</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%90%8E%E7%AB%AF/" rel="tag">后端</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%B7%A5%E5%85%B7/" rel="tag">工具</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E6%9E%B6%E6%9E%84/" rel="tag">架构</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E6%B5%81%E7%A8%8B/" rel="tag">流程</a><span class="tag-list-count">5</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E7%BC%96%E8%AF%91%E5%8E%9F%E7%90%86/" rel="tag">编译原理</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E7%BC%96%E8%AF%91%E5%8E%9F%E7%90%86%EF%BC%8C%E8%AF%BE%E7%A8%8B%E8%AE%BE%E8%AE%A1/" rel="tag">编译原理，课程设计</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E9%A1%B9%E7%9B%AE/" rel="tag">项目</a><span class="tag-list-count">6</span></li></ul>
        </canvas>
    </div>
</div>

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>


 




<div class="copyright">&copy; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">alexhigger</span>

  
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
    
      <span class="post-meta-item-text">Site words total count&#58;</span>
    
    <span title="Site words total count">34k</span>
  
</div>



<!--
  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>




  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Pisces</a> v5.1.4</div>
-->



        
<div class="busuanzi-count">
  <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv">
      <i class="fa fa-user"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
      
    </span>
  

  
    <span class="site-pv">
      <i class="fa fa-eye"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
      
    </span>
  
</div>








        
      </div>
    </footer>

    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "./public/search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  

  

  
  

  

  

  

  <!-- calendar widget -->


    <script src="/lib/CloudCalendar/CloudCalendar.js"></script>
    <script src="/lib/CloudCalendar/languages.js"></script>
    <script type="text/javascript">
    $(function() {
        $('#CloudCalendar').aCalendar('zh-CN', 
            $.extend(
                '', {
                    single:true,
                    root:'/calendar/'
                }
            )
        );
    });
    </script>



<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","model":{"jsonPath":"/live2dw/assets/wanko.model.json"},"display":{"position":"right","width":200,"height":400},"mobile":{"show":true},"log":false,"tagMode":false});</script></body>
</html>
